{include file="header.html"}
<body class="gr">

<div class="navBar">
	<a class="left" href="javascript:history.back()"><i class="return"></i></a>
	<div class="titleView-x">选择参保人</div>
	<a class="right" href="wap.php?app=cart&act=person_edit"><span>新建</span></a>
</div>

<div class="cart-person main-top">
	<div class="list">
		{foreach from=$data item=g}
		<div class="view" person-id="{$g->id}" person-name="{$g->name}">
			<div class="name ge-bottom">
				<a class="edit" href="wap.php?app=cart&act=person_edit&id={$g->id}"></a>
				{$g->name}
			</div>
			<span>手机号：{$g->mobile}</span>
			<span>身份证号：{$g->idcard}</span>
			<span>户籍类型：{$g->type}</span>
		</div>
		{foreachelse}
		<div class="norecord">没有任何记录</div>
		{/foreach}
	</div>
</div>

{include file="footer.html"}
<script>
$(function(){
	pushBodyView('.navBar .right, .cart-person .edit', function(bodyView){
		$('.cart-person-edit .front, .cart-person-edit .back').ajaxupload({
			url : 'api.php?app=cart&act=idcard_pic',
			name : 'idcard_pic',
			innerFile : false,
			before : function(){
				$.overload();
			},
			callback : {
				success : function(json, status){
					if(json.error!=0){ $.overloadError(json.msg);return }
					$(this).css('background-image', 'url('+json.data+')');
					$(this).find('input').val(json.data);
				},
				error : function(xml, status, e){
					alert('Upload error\n'+e);
				}
			}
		});
		$('.cart-person-edit .btn').click(function(){
			formBodyView(function(json){
				if(json.error!=0){ $.overloadError(json.msg);return }
				var delegate = delegateBodyView(bodyView);
				if(!delegate.length)return;
				reloadBodyView(delegate);
				popBodyView();
			});
		});
		pushBodyView('.cart-person-edit .view > a', function(bodyView){
			$('.cart-person-type .view a').click(function(){
				$(this).addClass('selected').siblings().removeClass('selected');
			});
			$('.cart-person-type .btn').click(function(){
				if(!$('.cart-person-type .selected').length){
					$.overloadError('请选择户籍类型');
					return;
				}
				var type = $('.cart-person-type .selected').text();
				var delegate = delegateBodyView(bodyView);
				if(!delegate.length)return;
				delegate.find('#type').val(type);
				delegate.find('.view > a .text').addClass('text-x').html(type);
				popBodyView();
			});
		});
	}, function(){
		var bodyView = this;
		$.getJSON('api.php?app=cart&act=person', function(json){
			if(json.error!=0){ $.overloadError(json.msg);return }
			var html = '';
			$.each(json.data, function(){
				html += '<div class="view" person-id="'+this.id+'" person-name="'+this.name+'">\
					<div class="name ge-bottom">\
						<a class="edit" href="wap.php?app=cart&act=person_edit&id='+this.id+'"></a>\
						'+this.name+'\
					</div>\
					<span>手机号：'+this.mobile+'</span>\
					<span>身份证号：'+this.idcard+'</span>\
					<span>户籍类型：'+this.type+'</span>\
				</div>';
			});
			bodyView.find('.list').html(html);
		});
	});
});
</script>